package com.ysw.rpc.common.config;

import lombok.Data;

import java.io.IOException;
import java.net.ServerSocket;

/**
 * @author YinShangwen
 * @since 2023/4/10 9:35
 */
@Data
public class RpcConfig {
    /**
     * 序列化方式
     * {@link Serializer.TypeMap}
     */
    private String serializer = "kryo";
    /**
     * 版本
     */
    private Integer version = 1;
    /**
     * 注册类型
     */
    private String register = "nacos";
    /**
     * 端口
     */
    private Integer port = -1;

    public Integer getPort() {
        try (ServerSocket socket = new ServerSocket(0)) {
            if (port <= 0) {
                port = socket.getLocalPort();
            }
            return port;
        } catch (IOException e) {
            return port;
        }
    }
}
